/**
 * @Title: Modal5.js
 * @Description: Modal5
 * @author: Fanchao
 * @date: 2021/2/14 3:41 下午
 * @version V1.0
 */
import React, { useState, useEffect } from 'react';
import { Form, InputNumber, Modal } from 'antd';
import { connect } from 'umi';

const Modal5 = ({ computeScheme: { tab5List, tab5Show, item5Data }, dispatch }) => {
    const [schoolExpertMinScore, setschoolExpertMinScore] = useState();
    const [schoolExpertMaxScore, setschoolExpertMaxScore] = useState();
    const [studentEvaluateMinScoreRatio, setstudentEvaluateMinScoreRatio] = useState();
    const [studentEvaluateMinScore, setstudentEvaluateMinScore] = useState();
    useEffect(() => {
        if (item5Data.notPassResultConditionId) {
            setschoolExpertMinScore(tab5List[0].conditionValueOne);
            setschoolExpertMaxScore(tab5List[0].conditionValueTwo);
            setstudentEvaluateMinScoreRatio(tab5List[1].conditionValueOne);
            setstudentEvaluateMinScore(tab5List[1].conditionValueTwo);
        } else {
            // console.log('no');
        }
    }, [item5Data.notPassResultConditionId]);
    return (
        <Modal
            title={'添加/修改不合格等级确定条件'}
            visible={tab5Show}
            // width="800px"
            onOk={() => {
                const params = {
                    schoolExpertMinScore,
                    schoolExpertMaxScore,
                    studentEvaluateMinScoreRatio,
                    studentEvaluateMinScore,
                };

                if (item5Data.notPassResultConditionId) {
                    dispatch({
                        type: 'computeScheme/updateTab5Item',
                        payload: params,
                        callback: (result) => {
                            if (result) {
                                dispatch({
                                    type: 'computeScheme/setItem5Data',
                                    payload: {},
                                });
                                dispatch({
                                    type: 'computeScheme/setTab5Show',
                                    payload: false,
                                });
                                dispatch({
                                    type: 'computeScheme/getTab5List',
                                });
                            }
                        },
                    });
                } else {
                    dispatch({
                        type: 'computeScheme/addTab5Item',
                        payload: params,
                        callback: (result) => {
                            if (result) {
                                dispatch({
                                    type: 'computeScheme/setItem5Data',
                                    payload: {},
                                });
                                dispatch({
                                    type: 'computeScheme/setTab5Show',
                                    payload: false,
                                });
                                dispatch({
                                    type: 'computeScheme/getTab5List',
                                });
                            }
                        },
                    });
                }
            }}
            onCancel={() => {
                dispatch({
                    type: 'computeScheme/setItem5Data',
                    payload: {},
                });
                dispatch({
                    type: 'computeScheme/setTab5Show',
                    payload: false,
                });
            }}
        >

            <div style={{ display: 'flex', alignItems: 'center' }}>
                <span style={{ marginRight: '10px' }}>校专家评分区间:</span>
                <InputNumber
                    min={0}
                    max={99}
                    step={0.1}
                    bordered={true}
                    placeholder="(包含)分"
                    value={schoolExpertMinScore}
                    onChange={(v) => setschoolExpertMinScore(v)}
                />
                <span style={{ margin: '0 10px' }}>&nbsp;&nbsp;-&nbsp;&nbsp;</span>
                <InputNumber
                    min={0}
                    max={99}
                    step={0.1}
                    bordered={true}
                    placeholder="(包含)分"
                    value={schoolExpertMaxScore}
                    onChange={(v) => setschoolExpertMaxScore(v)}
                />
                {/**/}
            </div>
            <div style={{ display: 'flex', alignItems: 'center', marginTop: '16px' }}>

                <span style={{ marginRight: '10px' }}>学员评分:</span>
                <InputNumber
                    min={0}
                    max={99}
                    step={0.1}
                    formatter={value => `${value}%`}
                    parser={value => value.replace('%', '')}
                    placeholder="百分比"
                    value={studentEvaluateMinScoreRatio}
                    onChange={(v) => setstudentEvaluateMinScoreRatio(v)}
                />
                <span style={{ margin: '0 10px' }}>以上评分均低于</span>
                <InputNumber
                    min={0}
                    max={99}
                    step={0.1}
                    bordered={true}
                    placeholder="(分数)"
                    formatter={value => `${value}分`}
                    parser={value => value.replace('分', '')}
                    value={studentEvaluateMinScore}
                    onChange={(v) => setstudentEvaluateMinScore(v)}
                />
            </div>
        </Modal>
    );
};

export default connect(({ computeScheme, dispatch }) => ({
    computeScheme,
    dispatch,
}))(Modal5);
